package com.rjpacket.supernews.app.databases;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by aaa on 15-3-12.
 */
public class DBHelper extends SQLiteOpenHelper {
    public DBHelper(Context context) {
        super(context, "NewsDb", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table myNews(_id integer primary key autoincrement," +
                "jsonNews text," +
                "channel text)");

        db.execSQL("create table myDetails(_id integer primary key autoincrement," +
                "nid text," +
                "jsonDetail text)");

        db.execSQL("create table myFavorite(_id integer primary key autoincrement," +
                "jsonNews text," +
                "position text)");

        db.execSQL("create table titles(_id integer primary key autoincrement,name text,checked integer,type text,id integer)");
        db.beginTransaction();
        try {
            ContentValues values = method("推荐", 1, "recommend", 1);
            db.insert("titles", null, values);

            values = method("热点", 1, "hotspot", 2);
            db.insert("titles", null, values);

            values = method("娱乐", 1, "entertainment", 3);
            db.insert("titles", null, values);

            values = method("教育", 0, "education", 4);
            db.insert("titles", null, values);

            values = method("朋友圈", 1, "friends", 5);
            db.insert("titles", null, values);

            values = method("旅游", 0, "traveling", 6);
            db.insert("titles", null, values);

            values = method("北京", 0, "local", 7);
            db.insert("titles", null, values);

            values = method("社会", 0, "society", 8);
            db.insert("titles", null, values);

            values = method("互联网", 0, "internet", 9);
            db.insert("titles", null, values);

            values = method("军事", 0, "military", 10);
            db.insert("titles", null, values);

            values = method("数码", 0, "digital", 11);
            db.insert("titles", null, values);

            values = method("爆料", 0, "baoliao", 12);
            db.insert("titles", null, values);

            values = method("健康", 0, "health", 13);
            db.insert("titles", null, values);

            values = method("时尚", 0, "fashion", 14);
            db.insert("titles", null, values);

            values = method("段子", 1, "jokes", 15);
            db.insert("titles", null, values);

            values = method("财经", 0, "finance", 16);
            db.insert("titles", null, values);

            values = method("活动专区", 0, "activityarea", 17);
            db.insert("titles", null, values);

            values = method("图片", 1, "photo", 18);
            db.insert("titles", null, values);

            values = method("汽车", 0, "car", 19);
            db.insert("titles", null, values);

            values = method("体育", 0, "sports", 20);
            db.insert("titles", null, values);

            values = method("房产", 0, "house", 21);
            db.insert("titles", null, values);

            values = method("游戏", 1, "play", 22);
            db.insert("titles", null, values);

            db.setTransactionSuccessful();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            db.endTransaction();
        }
//        db.close();
    }

    private ContentValues method(String name, int checked, String type, int id) {
        ContentValues values = new ContentValues();

        values.put("name", name);
        values.put("checked", checked);
        values.put("type", type);
        values.put("id", id);

        return values;
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
